package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.MesBom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.MesInspectionMapper;
import com.ruoyi.system.domain.MesInspection;
import com.ruoyi.system.service.IMesInspectionService;

/**
 * 质检管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-06-01
 */
@Service
public class MesInspectionServiceImpl implements IMesInspectionService 
{
    @Autowired
    private MesInspectionMapper mesInspectionMapper;

    /**
     * 查询质检管理
     * 
     * @param id 质检管理主键
     * @return 质检管理
     */
    @Override
    public MesInspection selectMesInspectionById(Integer id)
    {
        return mesInspectionMapper.selectMesInspectionById(id);
    }

    /**
     * 查询质检管理列表
     * 
     * @param mesInspection 质检管理
     * @return 质检管理
     */
    @Override
    public List<MesInspection> selectMesInspectionList(MesInspection mesInspection)
    {
        return mesInspectionMapper.selectMesInspectionList(mesInspection);
    }

    /**
     * 新增质检管理
     * 
     * @param mesInspection 质检管理
     * @return 结果
     */
    @Override
    public int insertMesInspection(MesInspection mesInspection)
    {
        return mesInspectionMapper.insertMesInspection(mesInspection);
    }

    /**
     * 修改质检管理
     * 
     * @param mesInspection 质检管理
     * @return 结果
     */
    @Override
    public int updateMesInspection(MesInspection mesInspection)
    {
        return mesInspectionMapper.updateMesInspection(mesInspection);
    }

    /**
     * 批量删除质检管理
     * 
     * @param ids 需要删除的质检管理主键
     * @return 结果
     */
    @Override
    public int deleteMesInspectionByIds(Integer[] ids)
    {
        return mesInspectionMapper.deleteMesInspectionByIds(ids);
    }

    /**
     * 删除质检管理信息
     * 
     * @param id 质检管理主键
     * @return 结果
     */
    @Override
    public int deleteMesInspectionById(Integer id)
    {
        return mesInspectionMapper.deleteMesInspectionById(id);
    }

    /**
     * 判断编码是否唯一
     * @param InspectionId 质检内容编码
     * @return
     */
    @Override
    public boolean isInspIdUnique(MesInspection mesInspection, Boolean addOrUpdate) {
        int count = mesInspectionMapper.countByInspId(mesInspection.getInspId());
        if(addOrUpdate) {
            return count == 0;
        }
        else {
            if(mesInspection.getInspId().equals(mesInspection.getOldInspId())){
                return count == 1;
            }
            else {
                return count == 0;
            }
        }
    }
}
